/**
 * @(#)IccIDUtils.java 2017年5月11日
 * Copyright(C) 2017年5月11日 ZHEXIN IT CO.,LTD. All rights reserved.
 */
package org.jsbd.boss.util;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.dubbo.common.utils.StringUtils;

/**
 * 模拟生成iccId
 * @author <a href="mailto:zhouchao@zhexinit.com" >周超</a>
 * @version 1.0.0
 */
public class IccIDUtils {
	public static final Logger LOGGER = LoggerFactory.getLogger(IccIDUtils.class);
	
	/**
	 * 手机号码段
	 */
	private static Map<String,String> phoneNumMap=new HashMap<String,String>();
	static{
		phoneNumMap.put("134", "4");
		phoneNumMap.put("135", "5");
		phoneNumMap.put("136", "6");
		phoneNumMap.put("137", "7");
		phoneNumMap.put("138", "8");
		phoneNumMap.put("139", "9");
		phoneNumMap.put("159", "0");
		phoneNumMap.put("158", "1");
		phoneNumMap.put("150", "2");
		phoneNumMap.put("151", "3");
		phoneNumMap.put("157", "a");
		phoneNumMap.put("188", "b");
		phoneNumMap.put("152", "c");
		phoneNumMap.put("147", "d");
		phoneNumMap.put("187", "e");
		phoneNumMap.put("183", "7");
		phoneNumMap.put("182", "9");
	}
	
	/**
	 * 省份对应关系
	 */
	private static Map<String,String> provinceNum=new HashMap<String,String>();
	static{
		provinceNum.put("0","01");
		provinceNum.put("1","02");
		provinceNum.put("2","09");
		provinceNum.put("3","31");
		provinceNum.put("4","08");
		provinceNum.put("5","07");
		provinceNum.put("6","06");
		provinceNum.put("7","05");
		provinceNum.put("8","29");
		provinceNum.put("9","27");
		provinceNum.put("10","30");
		provinceNum.put("11","26");
		provinceNum.put("12","04");
		provinceNum.put("13","15");
		provinceNum.put("14","03");
		provinceNum.put("15","16");
		provinceNum.put("16","25");
		provinceNum.put("17","24");
		provinceNum.put("18","22");
		provinceNum.put("19","23");
		provinceNum.put("20","20");
		provinceNum.put("21","19");
		provinceNum.put("22","13");
		provinceNum.put("23","18");
		provinceNum.put("24","17");
		provinceNum.put("25","14");
		provinceNum.put("26","11");
		provinceNum.put("27","10");
		provinceNum.put("28","12");
		provinceNum.put("29","28");
		provinceNum.put("30","21");
			

	}
	
	/**
	 * 生产年份
	 */
	private static List<String> yearList=new ArrayList<String>();
	static{
		yearList.add("01");
		yearList.add("02");
		yearList.add("03");
		yearList.add("04");
		yearList.add("05");
		yearList.add("06");
		yearList.add("07");
		yearList.add("08");
		yearList.add("09");
		yearList.add("10");
		yearList.add("11");
		yearList.add("12");
		yearList.add("13");
		yearList.add("14");
		yearList.add("15");
	}
	
	/**
	 * 厂商
	 * "0", "雅斯拓");
		"1", "GEMPLUS");
		"2", "武汉天喻");
		"3", "江西捷德");
		"4", "珠海东信和平 ");
		"5", "大唐微电子通");
		"6", "航天九州通");
		"7", "北京握奇");
		"8", "东方英卡");
		"9", "北京华虹A");
		"a", "上海柯斯");
	 */
	private static List<String> changsList=new ArrayList<String>();
	static{
		for(int i=0;i<10;i++){
			changsList.add(i+"");
		}
		changsList.add("a");
	}
	
	/**
	 * 
	 * 根据省份与手机号码获取移动iccId,如果创建失败，返回null
	 * @author <a href="mailto:zhouchao@zhexinit.com" >周超</a>
	 * @param province
	 * @param phoneNum
	 * @return
	 */
	public static String getYdIccId(int province,String phoneNum){
		StringBuffer iccId=new StringBuffer();
		iccId.append("898600");
		
		String firstTree=phoneNum.substring(0,3);
		String fourChar=phoneNum.substring(3,4);
		firstTree=getPhoneFirstThree(firstTree);
		if(StringUtils.isBlank(firstTree)){
			return null;
		}
		iccId.append(firstTree).append(fourChar);
		
		String provinceStr=provinceNum.get(province+"");
		if(StringUtils.isBlank(provinceStr)){
			return null;
		}
		iccId.append(provinceStr);
		iccId.append(yearList.get(RandomUtils.getRandomNum(yearList.size())));
		iccId.append(changsList.get(RandomUtils.getRandomNum(changsList.size())));
		iccId.append(MathUtils.getRandomString(7));
		return iccId.toString();
	}

	
	public static String getPhoneFirstThree(String firstTree){
		return phoneNumMap.get(firstTree);
	}
	
	
}
